package com.supor.aiot.mine.ui.adapter;

import android.text.TextUtils;

import com.android.baseconfig.common.utils.Util;
import com.android.baseconfig.recyclerview.adapter.BaseByViewHolder;
import com.android.baseconfig.recyclerview.adapter.BaseRecyclerAdapter;
import com.supor.aiot.common.utils.BitmapUtil;
import com.supor.aiot.mine.R;
import com.supor.aiot.mine.bean.IpsBean;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2020, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: IpsAdapter <br>
 * 作者: lei <br>
 * 日期: 2021/7/16 <br>
 */
public class IpsAdapter extends BaseRecyclerAdapter<IpsBean> {
    private HashMap<String, Integer> idMap = new HashMap<>();

    public IpsAdapter(List<IpsBean> dataList) {
        super(R.layout.item_ips, dataList);
    }

    public void setIdMap(HashMap<String, Integer> idMap) {
        this.idMap = idMap;
    }

    @Override
    protected void bindView(BaseByViewHolder<IpsBean> holder, IpsBean data, int position) {
        // if (!TextUtils.isEmpty(data.ipsImages)) {
        //     BitmapUtil.loadUrl(data.ipsImages, holder.itemView.findViewById(R.id.iv_icon));
        // } else {
        //     BitmapUtil.loadLocal(R.mipmap.ic_device_chief_machine, holder.itemView.findViewById(R.id.iv_icon));
        // }
        if (idMap != null && data.modelId != null) {
            Integer id = idMap.get(data.modelId);
            if (id != null) {
                BitmapUtil.loadLocal(id, holder.itemView.findViewById(R.id.iv_icon));
            }
        }
        if (!TextUtils.isEmpty(data.modelName)) {
            holder.setText(R.id.tv_name, data.modelName);
        } else {
            holder.setText(R.id.tv_name, "unknown");
        }
        if (!TextUtils.isEmpty(data.ipsDescription)) {
            holder.setText(R.id.tv_tip, data.ipsDescription);
        } else {
            holder.setText(R.id.tv_tip, "unknown");
        }
        if (!TextUtils.isEmpty(data.createTime)) {
            Date date = Util.parseDate(data.createTime);
            if (date != null) {
                holder.setText(R.id.tv_time, "提交时间：" + Util.getTime(date));
                return;
            }
        }
        holder.setText(R.id.tv_time, "unknown");
    }
}
